<?php
			ob_start();			
?>
<?php
		
		if (isset($_COOKIE["user"])) {
			// if cookie <> ""
		  }
		  else
		  {
			  header("location:login.php");
			  
		  }
?>
<?php
	if(isset($_REQUEST["user_id"]))
	{
		
		//select value from DB to show on textbox
		$user_id = $_REQUEST["user_id"];
		
		$sql = "SELECT * FROM tbl_user WHERE user_id={$user_id} LIMIT 1";
		$result = query($sql);
		$row = fetch_assoc($result);
		
		$user_id=$row["user_id"];	
		$userLogin=$row["user_login"];
		$published=$row["active"];

	}
?>
<?php
                    if(isset($_POST["btnsubmit"]))
                    {
						
						$user_id = $_POST["txtuser_id"];
						$userLogin=escapeValue($_POST["txtuserLogin"]);
						$newPassword=escapeValue($_POST["password"]);
						$confirmPassword=escapeValue($_POST["confirmPassword"]);
						$published=escapeValue($_POST["cbopublished"]);
						
						if($newPassword !=$confirmPassword)
						{
							errorMessage("Mot de passe est correspond pas ...!");
							
						}elseif($newPassword=="" ||$confirmPassword=="")
						{
							
							
										
										if(@$errors == "")
										{
											$sql = "UPDATE tbl_user SET user_login='$userLogin',active='$published'
												     WHERE user_id={$user_id}" ;													
											if(query($sql))
											{
												
												errorMessage("Mise à jour réussie ...!");
											}
										}
						}// end elseif newpass=confirmpass
						else
						{
								
										
										if(@$errors == "")
										{
											$sql = "UPDATE tbl_user SET user_login='$userLogin',  
													password='$confirmPassword',active='$published'
												     WHERE user_id={$user_id}" ;													
											if(query($sql))
											{
												
												errorMessage("Mise à jour réussie ...!");
																							
											}
										}
							
						}	
                    } //end isset btnsubmit
                ?>

                	<div id="border_cont_title">
                        	<div id='content_title_left'>modifier l'utilisateur </div>
                            <div id='content_title_right'></div>
					</div> <!--end border_cont_title-->
                    <?php echo @$errors;?>
                    	 <!--start table -->
                    <form action="index.php?page=userEdit" method="post" enctype="multipart/form-data">
                    	<table width="765px" align="left">
                        	
                            	<input type="hidden" value="<?php echo $user_id; ?>" name="txtuser_id" />
                             <tr>
                            	<td align="left" height="30" bgcolor="#FFEAD7">Connexion utilisateur</td>
                                <td>
                                <input type="text" name="txtuserLogin" value="<?php echo @$userLogin;?>" />
                                </td>
                            </tr>
                            <tr>
                            	<td align="left" height="30" bgcolor="#FFEAD7">Nouveau mot de passe</td>
                                <td>
                                <input type="password" name="password" value="" />
                                </td>
                            </tr>
                            <tr>
                            	<td align="left" height="30" bgcolor="#FFEAD7">Mot de passe comfirm</td>
                                <td>
                                <input type="password" name="confirmPassword" value="" />
                                </td>
                            </tr>
                            <tr>
                            	<td align="left" height="30" bgcolor="#FFEAD7">Publier</td>
                                <td align="left" height="30">
                                	<select name="cbopublished" >
                                       <option value=""> -- Sélectionnez Publier -- </option>
									<?php
										$sql = "SELECT * FROM tbl_zeroone";
                                    $result = query($sql);
                                    while($row = fetch_assoc($result))
                                    {
                                        
                                        if(@$published == $row['zeroone_value'])
                                            $selected = " selected='selected'";
											
                                        else	
                                            $selected = "";
                                	?>
                                        <option value="<?php echo $row['zeroone_value'];?>"<?php echo $selected;?>>
                                        <?php echo $row['zeroone_name'];?></option>
                                        
                                	<?php
										
                                    }
                                   
                                  	?>
                                        
                                    </select>
                                </td>
                            </tr>
                            <tr>
                            	<td align="left" height="30" bgcolor="#FFEAD7">Action</td>
                                <td align="left" height="30">
                                <input class="submit" type="submit" name="btnsubmit" value="Soumettre"  />
                                <input class="submit" type="button" name="btncancel" value="Annuler" onclick="redirect('index.php?page=user')" />
                                </td>
                            </tr>
                            
                        </table>
                        </form>
                    